package com.liyunc.demo.comp.captcha;

import com.liyunc.demo.comp.captcha.constant.CaptchaConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.annotation.PostConstruct;
import java.util.Objects;

/**
 * @author liyuncong
 * @version 1.0
 * @file CaptchaConfig
 * @brief CaptchaConfig
 * @details CaptchaConfig
 * @date 2022-06-08
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-06-08                      liyuncong          Created
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CaptchaConfig {

    private String sessionKeyImageCode;
    private Long expireTime;
    private char[] randString;

    private int imageWidth;
    private int imageHeight;
    private int imageLineSize;
    private int imageCharNumber;
    private int imageFontSize;

    @PostConstruct
    private void init() {
        if (Objects.isNull(sessionKeyImageCode)) {
            sessionKeyImageCode = CaptchaConstant.DEFAULT_SESSION_KEY_IMAGE_CODE;
        }
        if (Objects.isNull(expireTime)) {
            expireTime = CaptchaConstant.DEFAULT_EXPIRE_TIME;
        }
        if (Objects.isNull(randString) || randString.length <= 0) {
            randString = CaptchaConstant.DEFAULT_RAND_STRING;
        }
        if (imageWidth <= 0) {
            imageWidth = CaptchaConstant.imageWidth;
        }
        if (imageHeight <= 0) {
            imageHeight = CaptchaConstant.imageHeight;
        }
        if (imageLineSize <= 0) {
            imageLineSize = CaptchaConstant.imageLineSize;
        }
        if (imageCharNumber <= 0) {
            imageCharNumber = CaptchaConstant.imageCharNumber;
        }
        if (imageFontSize <= 0) {
            imageFontSize = CaptchaConstant.imageFontSize;
        }
    }
}
